<template>
	<view class="page_wrapper page_bg">
		<view class="body_block">
			<block v-if="data.originImgUrl">
				<view class="images_block">
					<image :src="data.originImgUrl" mode="aspectFill" class="user_exam_img" @tap="previewImage(data.originImgUrl)" />
					<image :src="data.newImgUrl" mode="aspectFill" class="user_exam_img" @tap="previewImage(data.newImgUrl)" />
				</view>
				<view class="data_stat_block">
					<view class="count_block total_count">总题数: <view class="count">{{data.rightCount + data.errorCount}}</view></view>
					<view class="count_block right_count">答对数: <view class="count">{{data.rightCount}}</view></view>
					<view class="count_block error_count">答错数: <view class="count">{{data.errorCount}}</view></view>
				</view>
			</block>
			<view class="prompt_title animate__animated animate__rubberBand my-anim" @click="uploadImg()">
				拍照批改口算
			</view>
			<view class="tip_block">tip: 小程序下载的口算题更容易批改识别^_^</view>
		</view>
	</view>
</template>

<script>
	import {request} from '@/utils/request.js'
	import {storageData} from '@/utils/storageData.js'
	export default {
		data() {
			return {
				data: {
					originImgUrl: '',
					newImgUrl: '',
					rightCount: 0,
					errorCount: 0,
					totalCount: 0
				}
			}
		},
		methods: {
			uploadImg() {
				const url = '/aiScans'
				
				// 检查是否有下载权限
				uni.showLoading()
				// request.get( 
				// 	'/userMathInfos/my', {}
				// ).then(res => {
				// 	uni.hideLoading()
				// 	console.log(res)
				// 	if(res.aiCheck){
				// 		request.uploadImg(url).then(res => {
				// 			const data = JSON.parse(res)
				// 			this.data = data
				// 			this.data.rightCount = parseInt(data.rightCount + '')
				// 			this.data.errorCount = parseInt(data.errorCount + '')
				// 		})
				// 	} else {
				// 		uni.showModal({
				// 			showCancel: false,
				// 			title: '分享一个好友后即可开通该功能'
				// 		})
				// 	}
					
				// }).catch(err => {
				// 	uni.hideLoading()
				// 	console.log(err)
				// })
				
			},
			previewImage(url) {
				uni.previewImage({
					urls: [url],
					longPressActions :{
						itemList:['保存图片'],
						success(data) {
							let imgurl = url
							that.saveImage(url)
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				})
			},
			saveImage(imgurl){
				// console.log(imgurl)
				uni.downloadFile({
					url:imgurl,
					success(res){
						// console.log(res)
						let url = res.tempFilePath
						uni.saveImageToPhotosAlbum({
							filePath:url,
							success() {
								uni.showToast({
									title:'保存成功',
									icon:"none"
								})
							},
							fail(err) {
								console.log('保存失败',err)
								uni.showToast({
									title:'保存失败',
									icon:"none"
								})
							}
						})
					}
				})
			}
		},
		onShareAppMessage(res) {
			const userInfo = storageData.getLoginUser()
			console.log(userInfo)
			if (res.from === 'button') {
					 // 来自页面内分享按钮
					 console.log(res.target);
			}
			return {
				title: '小奕口算：拍照批改口算',
				path: '/pages/aiScan/aiScan?shareUc=' + userInfo.userCode,
				mpId: 'wxcbbe1a868c5c3c3c', //此处配置微信小程序的AppId
			}
		},
		onShareTimeline(res) {
			const userInfo = storageData.getLoginUser()
			return {
				title: '小奕口算：拍照批改口算',
				path: '/pages/aiScan/aiScan?shareUc=' + userInfo.userCode,
				mpId: 'wxcbbe1a868c5c3c3c', //此处配置微信小程序的AppId
			}
		},
	}
</script>

<style lang="scss" scoped>
	.page_wrapper{
		.body_block{
			flex: 1;
			overflow-y: scroll;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			.images_block{
				width: 100%;
				display: flex;
				overflow: hidden;
				.user_exam_img{
					flex: 1;
				}
			}
			.data_stat_block{
				display: flex;
				flex-direction: column;
				font-size: 17px;
				margin: 10px 50px;
				.count_block{
					letter-spacing: 5px;
					display: flex;
					align-items: center;
					.count{
						font-size: 20px;
					}
				}
			}
			.prompt_title{
				display: inline-block;  
				width: 200px; /* 宽度和高度相同以形成圆形 */  
				height: 200px;  
				line-height: 200px; /* 垂直居中文本 */  
				text-align: center;  
				font-size: 24px; /* 增大字体以在圆形中更好地显示 */  
				font-weight: bold;  
				color: #fff;  
				text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5); /* 文本阴影，增强金属感 */  
				background: linear-gradient(to bottom, #a7a9ac, #888a8d); /* 渐变背景，使用银灰色调 */  
				border: none;  
				border-radius: 50%; /* 设置为50%以形成圆形 */  
				box-shadow:   
					inset 0 0 0 1px rgba(255,255,255,0.2), /* 内阴影，模拟金属光泽 */  
					0 2px 5px rgba(0, 0, 0, 0.2), /* 外阴影，增加立体感 */  
					0 5px 10px rgba(0, 0, 0, 0.1);  
				cursor: pointer;  
				transition: background 0.3s ease, box-shadow 0.3s ease;  
			}  
			
			.prompt_title:hover {  
				background: linear-gradient(to top, #888a8d, #a7a9ac); /* 悬停时改变渐变方向 */  
				box-shadow:   
					inset 0 0 0 1px rgba(255,255,255,0.3), /* 悬停时增强内阴影 */  
					0 4px 10px rgba(0, 0, 0, 0.3); /* 悬停时增强外阴影 */  
			}  
			
			.prompt_title:active {  
				background: #888a8d; /* 点击时背景色加深 */  
				box-shadow:   
					inset 0 2px 5px rgba(0, 0, 0, 0.2), /* 点击时内阴影加深 */  
					0 1px 2px rgba(0, 0, 0, 0.2); /* 点击时外阴影减少 */  
				transform: translateY(2px); /* 点击时按钮稍微下沉 */  
			}  
			
			.prompt_title::before {  
				content: "??"; /* 相机图标 */  
				margin-right: 5px;  
			}   
			
			.tip_block{
				color: #666666;
				margin-top: 30px;
			}
		}
		.results_block{
			display: flex;
			font-size: 17px;
			margin-bottom: 10px;
		}
		
		
		.my-anim{
			animation-duration: 2s;
			animation-delay: 0s;
			// 下面这个循环
			// animation-iteration-count: infinite;
		}
	
	}

</style>
